﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;

namespace homework2_bank.classes
{
    class Bank:BankCop
    {
        /**
         * 不同银行本身参数
         */
        public string name{set;get;}
        
        public Bank(string name1)
        {
            name = name1;
        }

        /**
         * 数据库模拟
         */
        //模拟中国银行-单例
        public static Bank zgyg = new Bank("中国银行");
        //模拟数据库操作，一条数据-单例
        public static UserAccount userAccount = new UserAccount("1234", "1234");
        public static BalanceArgs userBalance = new BalanceArgs("1234", "1234", 10000, 1000);

        /**
         * ATM传来的操作指令
         */
        //返回账号密码是否匹配
        public string MatchAccount(string account, string password)
        {
            if (account.Equals(userAccount.getAccount())&& password.Equals(userAccount.getPassword()))
            {
                return userAccount.getAccount();
            }
            else
            {
                return null;
            }
        }

        //返回当前的账户余额数据，只读
        public int[] GetBalanceArgs(string account)
        {
            if (account.Equals(userBalance.getAccount()))
            {
                int[] result = { userBalance.GetLeftBalance(), userBalance.GetCreditBalance() };
                return result;
            }
            else
            {
                return null;
            }
        }

        //存钱
        public bool AddMoney(string account, int num)
        {
            if (account.Equals(userBalance.getAccount()))
            {
                return userBalance.MoneyIn(num);
            }
            else
            {
                return false;
            }
        }

        //取钱
        public int TakeMoney(string account, int num)
        {
            //-3表示账号不匹配，-2表示余额不足，-1表示未知错误，0表示成功
            if (account.Equals(userBalance.getAccount()))
            {
                return userBalance.MoneyOut(num);
            }
            else
            {
                return -3;
            }
        }

        //银行大额取款备案--订阅
        public void BigMoneyWarn(BigMoneyFetched bigMoneyFetched)
        {
            string msg = "银行收到大额取款备案，账号：" + bigMoneyFetched.GetAccount() + "，额度：" + bigMoneyFetched.GetNum();
            MessageBox.Show(msg);
        }
    }
}
